﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace entity
{
    public class ApiContext:DbContext
    {
        public ApiContext(DbContextOptions<ApiContext> opts):base(opts) { 
        
        }

        public DbSet<EntityUser> EntityUser { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            EntityUser user = new EntityUser();
            user.FirstName = "123123";
            user.LastName = "3463";


            modelBuilder.Entity<EntityUser>().HasData(
                new EntityUser
                {
                    FirstName = "1",
                    LastName = "2",
                    Email = "4444"
                }
            );
        }

    }
    class ApiDBContextFactory : IDesignTimeDbContextFactory<ApiContext>
    {

        public ApiContext CreateDbContext(string[] args)
        {
            var optionBuilder = new DbContextOptionsBuilder<ApiContext>();
            optionBuilder.UseMySql(
                "server=localhost;userid=root;password=123456;database=AIYDB;port=3306;",
                new MySqlServerVersion(new Version(8, 0, 41))
                );

            return new ApiContext(optionBuilder.Options);
        }
    }
}

